package com.apeli.model;

import com.apeli.design.OrderConsumer;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;

@Component
public class User implements BeanNameAware, InitializingBean {

    private String name;

    private Integer age;

    public User() {
        System.out.println("实例化bean...");
    }

    public User(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    public void call() {
        System.out.println("call...");
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public void init () {
        System.out.println("初始化方法....init");
    }

    @Override
    public void setBeanName(String name) {
        System.out.println("属性填充...");
        System.out.println("aware 接口回调 ....setBeanName");
    }

    @PostConstruct
    public void post() {
        System.out.println("初始化前操作...@PostConstruct");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("bean...初始化");
    }

    //    public static void main(String[] args) {
//        Map<String,String> map = new HashMap<>();
//        map.put("1","aa");
//        map.put("2","bb");
//        map.put("3","cc");
//        System.out.println(map.computeIfAbsent("2", e -> "3"));
////        System.out.println(getCurrentName("4", map));
//    }
//
//    public static String getCurrentName(String name,Map<String,String> map) {
//        String currentName = name;
//        String reslveName;
//        do{
//            reslveName = map.get(currentName);
//            if (reslveName != null) {
//                currentName = reslveName;
//            }
//        } while (reslveName != null);
//        return currentName;
//    }
}
